<template>
	<view class="">
		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :back-top="true">
			<view class="item-swiper" style="padding-top: 20upx;">
				<view class="item" v-for="(item, index) in dataList" :key="index">
					<view class="item-top row between">
						<view class="line"></view>
						<view class="item-t-l">
							<view class="item-money" v-if="item.type==0" style="font-size: 36upx;">体验券</view>
							<view class="" v-else>
								<view class="item-money b-m">{{item.money}}</view>
								<view class="item-t-t">优惠券</view>
							</view>
						</view>
						<view class="row between fill" style="padding-left:30upx;">
							<view class="">
								<view class="item-title" v-if="item.type==0">新用户{{item.money}}洗衣券</view>
								<view class="item-title" v-else>平台赠送</view>
								<view class="item-d" v-if="item.type==1">订单满{{item.reach}}元可用</view>
							</view>
							<view class="item-name canuse" hover-class="hover-opacity"  @tap="useTap(item)">立即使用</view>
						</view>
					</view>
					<view class="item-bottom row between">
						<view class="item-b-l">有效期：{{item.startTime | YMD}}~{{item.endTime | YMD}}</view>
						<navigator class="item-b-r" url="/pages/public/webView">使用规则</navigator>
					</view>
				</view>
			</view>
		</s-pull-scroll>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
export default {
	data() {
		return {
			dataList:[],
			goodsIds:"",
			sum:""
		};
	},
	onLoad(options) {
		this.goodsIds=options.goodsIds;
		console.log(this.goodsIds)
		this.sum=options.sum;
		this.refresh();
	},
	methods: {
		useTap(item){
			if(item.goodsIds && item.type==0){
				let a=this.goodsIds.split(',');
				let b=item.goodsIds.split(',');
				let c=new Set([...a,...b]);
				let abl=a.length+b.length;
				if(c.size==abl){
					this.$util.msg('该劵指定衣物可用!');
					return
				}
			}else{
				if(this.sum>item.reachPrice){
					this.$util.msg('该劵不满足使用条件!');
					return
				}
			}
			this.$util.prePage().compline=item;
			this.back();
		},
		change(index) {
			this.current = index;
			this.refresh();
		},
		pullDown(pullScroll) {
			setTimeout(() => {
				this.loadData(pullScroll);
			}, 200);
		},
		async loadData(pullScroll) {
			const data = {
				uid: uni.getStorageSync('uid'),
				goodsIds:this.goodsIds,
				sum:this.sum,
				pageNo: pullScroll.page,
				pageSize: '10'
			};
			const res = await this.$request('coupon/can-use', data, { showLoading: true });
			if (pullScroll.page == 1) this.dataList = [];
			if (res.result == 0) {
				this.dataList = this.dataList.concat(res.data.list);
				pullScroll.endByPage(Math.ceil(res.data.count / 10), res.data.list);
			} else {
				this.$util.msg(res.resultNote);
			}
		}
	}
};
</script>
<style>
page {
	background: #f6f6f6;
}
</style>

<style scoped lang="scss">
.item {
	width: 700upx;
	margin: 0 auto 20upx;
	height: 260upx;
	position: relative;
}
.item-top {
	height: 180upx;
	background: #ffffff;
	padding: 20upx;
	box-shadow: -5px 0px 49upx 0px rgba(204, 204, 204, 0.3);
	border-radius: 16upx 16upx 0px 0px;
	position: relative;
}
.item-bottom {
	height: 80upx;
	background: #fbfafa;
	padding: 20upx;
	border-radius: 0px 0px 16upx 16upx;
}
.item-b-l {
	font-size: 24upx;
	color: #999999;
}
.item-b-r {
	font-size: 24upx;
	color: #666666;
}
.item-t-t {
	font-size: 24upx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ff8091;
}
.b-m::before {
	content: '￥';
	font-size: 24upx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #fe2525;
}
.line {
	width: 1px;
	height: 64upx;
	background: #e7e7e7;
	position: absolute;
	left: 160upx;
	top: 60upx;
}
.item-money {
	width: 140upx;
	font-size: 40upx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #fe2525;
}
.item-title {
	font-size: 32upx;
	font-weight: bold;
	color: #333333;
}
.item-d {
	font-size: 24upx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #666666;
	padding-top: 8upx;
}
.item-name {
	width: 140upx;
	height: 50upx;
	text-align: center;
	line-height: 50upx;
	border-radius: 25upx;
	font-size: 22upx;
	color: #ffffff;
}
.canuse {
	background: #6aae59;
}
.hasuse {
	background: #2781a7;
}
.nouse {
	background: #cccccc;
}
</style>
